<?php
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Translate.php';
require_once 'Zend/Registry.php';
require_once 'gcConfigRegistry.php';
require_once 'application/library/helper/configHelper.php';
require_once 'application/constant/constant.php';

/**
 * gcConfigAction
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class gcConfigAction {
//TODO ini需整理
    /**
     * 全局变量config读取
     * temporaryConfig
     */
    public static function temporaryConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::VARIABLE)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_VARIABLE_PATH,sysConstant::GLOBAL_CONFIG);
            gcConfigRegistry::setZend(sysConstant::VARIABLE, $config->toArray());
            gcConfigRegistry::set(sysConstant::VARIABLE, $config->toArray());
        }else {
            gcConfigRegistry::setZend(sysConstant::VARIABLE, gcConfigRegistry::get(sysConstant::VARIABLE));
        }
    }

    /**
     * 系统config读取
     * loaderSYSConfig
     */
    public static function loaderSYSConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::APPCONFIG_SYS)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::APPCONFIG_SYS);
            gcConfigRegistry::setZend(sysConstant::APPCONFIG_SYS, $config->toArray());
            gcConfigRegistry::set(sysConstant::APPCONFIG_SYS, $config->toArray());
        }else{
            gcConfigRegistry::setZend(sysConstant::APPCONFIG_SYS, gcConfigRegistry::get(sysConstant::APPCONFIG_SYS));
        }
    }

    /**
     * DBConfig读取
     * loaderDBConfig
     */
    public static function loaderDBConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::DB_NAME_EPSITE)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_DB_PATH, sysConstant::DB_NAME_EPSITE);
            gcConfigRegistry::set(sysConstant::DB_NAME_EPSITE, $config->toArray());
        }else {}
    }

    /**
     * 信息config读取
     * loaderMessageConfig
     */
    public static function loaderMessageConfig(){
        $localLanguage=configHelper::getLocalLanguage();
        if(!gcConfigRegistry::isRegistered(sysConstant::SYS_TRANSLATE)){
            $translate = new Zend_Translate(array(
                                          "adapter" => "tmx",
                                          "content" => sysConstant::APP_LANGUAGES_DIRECTORY,
                                          "locale"  => $localLanguage));
            gcConfigRegistry::set(sysConstant::SYS_TRANSLATE, serialize($translate));
        }else {}
    }

    /**
     * 读取访问限制config
     * loaderUriInterceptConfig
     */
    public static function loaderUriInterceptConfig() {
        if(!gcConfigRegistry::isRegistered(sysConstant::URI_INTERCEPT)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::URI_INTERCEPT);
            gcConfigRegistry::setZend(sysConstant::URI_INTERCEPT, $config->toArray());
            gcConfigRegistry::set(sysConstant::URI_INTERCEPT, $config->toArray());
        }else {
            gcConfigRegistry::setZend(sysConstant::URI_INTERCEPT, gcConfigRegistry::get(sysConstant::URI_INTERCEPT));
        }
    }
    /**
     * smartyconfig读取
     * loaderSmartyConfig
     */
    public static function loaderSmartyConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::SMARTY)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::SMARTY);
            gcConfigRegistry::setZend(sysConstant::SMARTY, $config->toArray());
            gcConfigRegistry::set(sysConstant::SMARTY, $config->toArray());
        }else {
            gcConfigRegistry::setZend(sysConstant::SMARTY, gcConfigRegistry::get(sysConstant::SMARTY));
        }
    }

    
    /**
     * 系统MAILconfig读取
     * loaderSYSConfig
     */
    public static function loaderMailConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::MAIL)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::MAIL);
            gcConfigRegistry::setZend(sysConstant::MAIL, $config->toArray());
            gcConfigRegistry::set(sysConstant::MAIL, $config->toArray());
        }else{
            gcConfigRegistry::setZend(sysConstant::MAIL, gcConfigRegistry::get(sysConstant::MAIL));
        }
    }

    /**
     * 支付宝config读取
     * loadAlipayConfig
     */
    public static function loadAlipayConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::ALIPAY)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::ALIPAY);
            gcConfigRegistry::set(sysConstant::ALIPAY, $config->toArray());
        }else{}
    }

    /**
     * FTP服务主机
     * loadFtpSvr
     */
    public static function loadFtpSvr(){
        if(!gcConfigRegistry::isRegistered(sysConstant::FTPSVR)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::FTPSVR);
            gcConfigRegistry::set(sysConstant::FTPSVR, $config->toArray());
        }else{}
    }

    /**
     * domain读取
     * loaderDomainConfig
     */
    public static function loaderDomainConfig(){
        if(!gcConfigRegistry::isRegistered(sysConstant::SAVE_DOMAIN_CONFIG)){
            $config=new Zend_Config_Ini(sysConstant::CONFIG_APP_PATH,sysConstant::DOMAIN);
            gcConfigRegistry::setZend(sysConstant::SAVE_DOMAIN_CONFIG, $config->toArray());
            gcConfigRegistry::set(sysConstant::SAVE_DOMAIN_CONFIG, $config->toArray());
        }else {
            gcConfigRegistry::setZend(sysConstant::SAVE_DOMAIN_CONFIG, gcConfigRegistry::get(sysConstant::SAVE_DOMAIN_CONFIG));
        }
    }
}